﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BonsaiScrum.Core.Persistance;
using BonsaiScrum.Core.Query;
using NHibernate;
using System.Collections.ObjectModel;
using NHibernate.Criterion;

namespace BonsaiScrum.Data.Reporting
{
    public class NHibernateProjectReportingRepository : IProjectReportingRepository
    {
        private ISession _session;

        public NHibernateProjectReportingRepository(ISession session)
        {
            _session = session;
        }

        public ICollection<ProjectReport> GetAllProjects()
        {
            ICriteria criteria = _session.CreateCriteria<ProjectReport>();

            return new Collection<ProjectReport>(criteria.List<ProjectReport>());
        }

        public ProjectReport GetProjectWithId(int id)
        {
            return _session.Get<ProjectReport>(id);
        }


        public ICollection<ProjectReport> GetAllActiveProjectsForUser(int userId)
        {
            throw new NotImplementedException();
        }

        public ICollection<ProjectReport> GetAllActiveProjects()
        {
            var projects = _session.CreateCriteria<ProjectReport>()
                .Add(Expression.Eq("Status", ProjectStatus.Active))
                .List<ProjectReport>();

            return projects;
        }

        public ICollection<SprintReport> GetAllSprintsForProject(int projectid)
        {
            var sprints = _session.CreateCriteria<SprintReport>()
                .Add(Expression.Eq("ProjectID", projectid))
                .List<SprintReport>();

            return sprints;
        }
    }
}
